{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import open3d as o3d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#draw a point cloud with default parameter\n",
    "dataset = o3d.data.PLYPointCloud()\n",
    "office = o3d.io.read_point_cloud(dataset.path)\n",
    "o3d.visualization.draw_plotly([office])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#we can downsample these points to speed up visualization by adjusting \n",
    "# point_sample_factor to a smaller number\n",
    "dataset = o3d.data.PLYPointCloud()\n",
    "office = o3d.io.read_point_cloud(dataset.path)\n",
    "o3d.visualization.draw_plotly([office], point_sample_factor=0.1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#adjust the camera to get a better view\n",
    "dataset = o3d.data.PLYPointCloud()\n",
    "office = o3d.io.read_point_cloud(dataset.path)\n",
    "o3d.visualization.draw_plotly([office],\n",
    "                              point_sample_factor=0.1,\n",
    "                              zoom=0.3,\n",
    "                              front=[0.4257, -0.2125, -0.8795],\n",
    "                              lookat=[2.672, 2.0475, 1.532],\n",
    "                              up=[-0.0694, -0.9768, -0.2024])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#draw a triangle mesh\n",
    "dataset = o3d.data.BunnyMesh()\n",
    "mesh = o3d.io.read_triangle_mesh(dataset.path)\n",
    "o3d.visualization.draw_plotly([mesh],\n",
    "                              up=[0, 1, 0],\n",
    "                              front=[0, 0, 1],\n",
    "                              lookat=[0.0, 0.1, 0.0],\n",
    "                              zoom=0.5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#draw a triangle mesh with wireframes.\n",
    "dataset = o3d.data.BunnyMesh()\n",
    "mesh = o3d.io.read_triangle_mesh(dataset.path)\n",
    "o3d.visualization.draw_plotly([mesh],\n",
    "                              mesh_show_wireframe=True,\n",
    "                              up=[0, 1, 0],\n",
    "                              front=[0, 0, 1],\n",
    "                              lookat=[0.0, 0.1, 0.0],\n",
    "                              zoom=0.5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#draw a point set\n",
    "points = [\n",
    "    [0, 0, 0],\n",
    "    [1, 0, 0],\n",
    "    [0, 1, 0],\n",
    "    [1, 1, 0],\n",
    "    [0, 0, 1],\n",
    "    [1, 0, 1],\n",
    "    [0, 1, 1],\n",
    "    [1, 1, 1],\n",
    "]\n",
    "lines = [\n",
    "    [0, 1],\n",
    "    [0, 2],\n",
    "    [1, 3],\n",
    "    [2, 3],\n",
    "    [4, 5],\n",
    "    [4, 6],\n",
    "    [5, 7],\n",
    "    [6, 7],\n",
    "    [0, 4],\n",
    "    [1, 5],\n",
    "    [2, 6],\n",
    "    [3, 7],\n",
    "]\n",
    "colors = [[1, 0, 0] for i in range(len(lines))]\n",
    "line_set = o3d.geometry.LineSet(\n",
    "    points=o3d.utility.Vector3dVector(points),\n",
    "    lines=o3d.utility.Vector2iVector(lines),\n",
    ")\n",
    "line_set.colors = o3d.utility.Vector3dVector(colors)\n",
    "o3d.visualization.draw_plotly([line_set])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  },
  "vscode": {
   "interpreter": {
    "hash": "3ec8595b82bcf0a9f1a7e32ed14cfe97e39431d14008eeea742839d858b14727"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
